use [hanhuddb]
Go
IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Pages_InsertPage') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Pages_InsertPage
GO
CREATE PROCEDURE [dbo].Pages_InsertPage
(
	@Module			varchar(50),
	@Name			varchar(50),
	@Title			nvarchar(256),
	@Description	nvarchar(500),
	@Keywords		nvarchar(500)	
)
AS
BEGIN
	IF (EXISTS(SELECT * FROM Pages WHERE Module = @Module AND Name = @Name)) RETURN -1

	INSERT Pages(Module, Name, Title, Description, Keywords, PValue)
	VALUES (@Module, @Name, @Title, @Description, @Keywords, 1)
	
	RETURN @@identity
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Pages_UpdatePage') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Pages_UpdatePage
GO
CREATE PROCEDURE [dbo].Pages_UpdatePage
(
	@Module			varchar(50),
	@Name			varchar(50),
	@Title			nvarchar(256),
	@Description	nvarchar(500),
	@Keywords		nvarchar(500)	
)
AS
BEGIN
	UPDATE Pages
	SET
		Title		= @Title,
		Description = @Description,
		Keywords	= @Keywords

	WHERE Module = @Module AND Name = @Name
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Pages_DeletePage') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Pages_DeletePage
GO
CREATE PROCEDURE [dbo].Pages_DeletePage
(
	@Module			varchar(50),
	@Name			varchar(50)
)
AS
BEGIN
	DELETE Pages WHERE Module = @Module AND Name = @Name
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Pages_GetPages') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Pages_GetPages
GO

CREATE PROCEDURE [dbo].Pages_GetPages
AS
BEGIN
	SELECT Module, Name, Title, Description, Keywords, PValue 
	FROM Pages
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Pages_GetPage') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Pages_GetPage
GO

CREATE PROCEDURE [dbo].Pages_GetPage
(
	@Module			varchar(50),
	@Name			varchar(50)
)
AS
BEGIN
	SELECT Module, Name, Title, Description, Keywords, PValue 
	FROM Pages 
	WHERE Module = @Module AND Name = @Name
END
